package com.xcf.dubbo.service.impl;

import com.xcf.common.FilterConstant;
import com.xcf.dubbo.service.ServerService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;

import java.util.Random;

@Service
public class DubboServerServiceImpl implements ServerService {

    @Override
    public String doIp() {
        return RpcContext.getContext().getAttachment(FilterConstant.VISIT_IP_KEY);
    }

    private String randomSleep() {
        Random random = new Random();
        int sleepTime = random.nextInt(101);
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return String.valueOf(sleepTime);
    }

    @Override
    public String methodA() {
        return randomSleep();
    }

    @Override
    public String methodB() {
        return randomSleep();
    }

    @Override
    public String methodC() {
        return randomSleep();
    }
}
